package org.nowcoder.huawei.c200;

/**
 * 1: 查找接口成功率最优时间段
 */
public class HC001 {
    public static void main(String[] args) {
        solve(new int[]{0, 0, 0, 2, 2, 0, 0, 2}, 2);
    }

    public static void solve(int[] nums, int minAvgLost) {
        if (nums[0] >= minAvgLost) {
            return;
        }

        int left = 0, right = 0;
        int max = Integer.MIN_VALUE;
        String result = null;
        while (right < nums.length) {
            int v = nums[right];
            if (v <= minAvgLost) {
                right++;
            } else {
                int var = right - left;
                if (max < var) {
                    max = var;
                    result = left + "-" + (right - 1);
                } else if (max == var) {
                    result += " " + left + "-" + (right - 1);
                }
                while (right < nums.length && nums[right] > minAvgLost) {
                    right++;
                }
                left = right;
            }
        }
        int var = right - left;
        if (max < var) {
            result = left + "-" + (right - 1);
        } else if (max == var) {
            result += " " + left + "-" + (right - 1);
        }
        System.out.println(result);
    }
}
